package com.atguigu.Controller;


import cn.hutool.core.util.IdUtil;
import com.atguigu.Annoton.myannotion;
import com.atguigu.resp.ResultData;
import com.atguigu.resp.ResultData2;
import com.atguigu.resp.ReturnCodeEnum2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class mycontroller2 {

    @GetMapping("/m1")
    public ResultData<Boolean> m1() {
        long startTime = System.currentTimeMillis();
        System.out.println("---------方法前，come in");

        System.out.println(("主业务流程订单编号：" + IdUtil.randomUUID()));

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("-------costTime: "+(endTime-startTime)+"毫秒");

        return ResultData.success(true);
    }

    @GetMapping("/m2")
    @myannotion(value = "java0923 yyds",enable = true)
    public ResultData m2(){
        long startTime = System.currentTimeMillis();

        System.out.println(("主流程业务编号" + IdUtil.randomUUID()));

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long endTime = System.currentTimeMillis();
        System.out.println("-------costTime: "+(endTime-startTime)+"毫秒");
        return ResultData.success(true);
    }

    @GetMapping("/m3")
    @myannotion(enable = false)
    public ResultData m3(){
        long startTime = System.currentTimeMillis();

        System.out.println(("主业务流程" + IdUtil.randomUUID()));
        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("-------costTime: "+(endTime-startTime)+"毫秒");
        return ResultData.success("true");
    }

    @GetMapping(value = "/m4")
    public ResultData2<String> m4(){
        System.out.println("come in m4");

        try {
            System.out.println("m4 task over");
            int age =10/0;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData2.fail(ReturnCodeEnum2.RC204.getCode(), ReturnCodeEnum2.RC204.getMessage()+"\t"+e.getMessage());
        }
        return ResultData2.success("0923 java good");

    }

    @GetMapping(value = "/m5")
    public ResultData2<Integer> m5(){
        System.out.println("come in m5");

        try {
            System.out.println("m5 task over "+"240923");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData2.fail(ReturnCodeEnum2.RC999.getCode(), ReturnCodeEnum2.RC999.getMessage());
        }
        return ResultData2.success(240923);

    }



}
